<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_info_model extends CI_Model {
	function __construct(){
        parent::__construct();
    }
    
    function add($data = array()){
		$this->db->insert('zjy_user_info', $data);
		return $this->db->affected_rows();
    }
    
    
    function update($data = array(),$where = array()){
		$this->db->where($where);
		$this->db->update('zjy_user_info', $data);
		$res = $this->db->affected_rows();
		if($res > 0 && isset($where['user_id'])){
			$key = 'zjy_user_info_'.$where['user_id'];
			$this->mycache->delete($key);
		}
		return $res;
    }
    
    function get_one($where = array(),$select='*'){
		$this->db->select($select);
		if($where){
			$this->db->where($where);
		}
		$this->db->limit(1);
		$query = $this->db->get('zjy_user_info');
		return $query->row_array();
	}
	
	function get_by_uid($user_id){
		$key = 'zjy_user_info_' . $user_id;
		$row = $this->mycache->get_array($key);
		if($row == false){
			$this->db->where('user_id',$user_id);
			$query = $this->db->get('zjy_user_info');
			$row = $query->row_array();
			if($row){
				$this->mycache->set_array($key,$row);
			}
		}
		return $row;
	}

}